<?php
class DepartmentAction extends Action {
    public function departments(){
        
        $departments = new Model('departments');
        $data = $departments->join('dept_manager on departments.dept_no = dept_manager.dept_no')
                            ->join('employees on dept_manager.emp_no = employees.emp_no')
                            ->select();
        $this->assign('departments', $data);
        $departmentsCount = $departments->Count();
        $this->assign('departmentsCount', $departmentsCount);

        $employees = new Model('employees');
        $employeesCount = $employees->Count();
        $this->assign('employeesCount', $employeesCount);
        $title = 'Departments | EMS System';
        $this->assign('title', $title);
        $this->display();
    }

    public function department(){
        
        $departments = M('departments');
        $dept_no = $this->_param('id');
        $condition = array('dept_no'=> $dept_no);
        $department = $departments->where($condition)->find();
        $this->assign('department', $department);
        
        $employee = M('dept_emp');
        $employeeCount = $employee->where($condition)->count('emp_no');
        $this->assign('employeeCount', $employeeCount);

        $this->display();
    }
}
